package com.sun.springbootfiledownload.controller;

import com.sun.springbootfiledownload.result.AliyunOssResult;
import com.sun.springbootfiledownload.utils.AliyunOssPlusUtil;
import com.sun.springbootfiledownload.utils.AliyunOssUtil;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/oss")
public class AliyunOssPlusController {

    private final AliyunOssPlusUtil aliyunOssUtil;

    public AliyunOssPlusController(AliyunOssPlusUtil aliyunOssUtil) {
        this.aliyunOssUtil = aliyunOssUtil;
    }

    @PostMapping("/upload")
    public AliyunOssResult upload(@RequestParam("file") MultipartFile file) {
        return aliyunOssUtil.upload(file);
    }

    @PostMapping("/upload-to-dir")
    public AliyunOssResult uploadToDir(@RequestParam("file") MultipartFile file,
                                       @RequestParam("dir") String dir) {
        return aliyunOssUtil.upload(file, dir);
    }

    @GetMapping("/temp-url")
    public String getTempUrl(@RequestParam String filePath) {
        return aliyunOssUtil.getTempUrl(filePath);
    }

    @GetMapping("/delete")
    public boolean deleteFile(@RequestParam String filePath) {
        return aliyunOssUtil.deleteFile(filePath);
    }
}